Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply runtime library workaround for snapshot toolchains on macOS #484

Merged
merged 14 commits into from
Jun 10, 2024

Conversation

omochi
Copy link
Contributor

@omochi omochi commented Jun 10, 2024

swiftlang/swift#73327 (comment) のハックを Carton に組み込む

動作の様子

コード署名し直すことを黄色で予告して、コマンドラインを表示しました。
また、ついでに見た目の改善としてコマンドライン実行時の不足している改行を追加したり、余計な空行を削除したりしました。

スクリーンショット 2024-06-10 13 55 20 スクリーンショット 2024-06-10 13 55 30

guard fileSystem.isFile(file) else { continue }

let process = Foundation.Process()
process.executableURL = URL(fileURLWithPath: "/usr/bin/sudo")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need sudo as long as the toolchain is installed under ~/Library/Toolchain/ if I remember correctly, and we can assume it's installed there by carton

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あ、そうなの
試してみます

Copy link
Contributor Author

@omochi omochi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self comment

printsLoadingMessage: Bool = true,
forwardExit: Bool = false
) throws {
let process = Foundation.Process()
process.executableURL = executableURL
process.arguments = arguments
process.environment = environment
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkRunに環境変数の設定する口を開けました。

let pluginArguments = try derivePackageCommandArguments(
swiftExec: swiftExec,
subcommand: subcommand,
scratchPath: scratchPath.path,
extraArguments: extraArguments
)

var env: [String: String] = ProcessInfo.processInfo.environment
if ToolchainSystem.isSnapshotVersion(swiftPath.verison),
swiftPath.toolchain.extension == "xctoolchain"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mac環境かつsnapshotなら、DYLD... を設定します。

@@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if compiler(>=5.10)
#if compiler(>=6.0)
public let defaultToolchainVersion = "wasm-6.0-SNAPSHOT-2024-06-08-a"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6.0のsnapshotを追加します。
CIのSwift6.0が swift-6.0-DEVELOPMENT-SNAPSHOT-2024-06-07-a になっていて、
それと対応する wasm swift にしています。
だから1日ズレています。

@@ -94,7 +94,6 @@ extension Process {

switch result.map(\.exitStatus) {
case .success(.terminated(code: EXIT_SUCCESS)):
terminal.write("\n")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この改行が不要そうでした。

@@ -103,7 +102,7 @@ extension Process {
terminal.write(stdoutBuffer)
}
terminal.write(
"\n`\(processName)` process finished successfully\n",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この冒頭の改行も不要だと思いました。

@@ -65,6 +66,8 @@ extension ToolchainSystem {
stream: stdoutStream,
header: "Downloading the archive"
)
defer { terminal.write("\n") }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ダウンロードが完了した時
Download completed successfully
のメッセージが saving to ... の右に表示されていておかしかったので、改行を入れます。

ここはターミナルがアニメーションするループがあるので、
エラーの場合もうまくいくように
defer でここに書きます。

@@ -109,6 +112,32 @@ extension ToolchainSystem {
terminal.logLookup("Unpacking the archive: ", arguments.joined(separator: " "))
try await Process.run(arguments, terminal)

if ext == "pkg", Self.isSnapshotVersion(version) {
try await patchSnapshotForMac(path: installationPath, terminal: terminal)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

インストール後にmacでsnapshotならパッチ(再署名)します。

for file in try fileSystem.traverseRecursively(binDir) {
guard fileSystem.isFile(file) else { continue }

try Foundation.Process.checkRun(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

出力がスッキリするので Foundation.Process.checkRun を使いました。

public var verison: String
public var swift: AbsolutePath
public var toolchain: AbsolutePath
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

従来、swiftとバージョンのタプルでしたが、
ツールチェーンディレクトリも使いたくなったので追加します。

ついでにタプルをやめて型にすることで利用側のコードを読みやすくします。

@omochi omochi changed the title [WIP] macにsnapshot版のツールチェーンを入れるときは9999問題を回避する作業をする macにsnapshot版のツールチェーンを入れるときは9999問題を回避する作業をする Jun 10, 2024
@omochi omochi marked this pull request as ready for review June 10, 2024 05:05
@omochi
Copy link
Contributor Author

omochi commented Jun 10, 2024

あれ、CI失敗だ

error: 'testapp': Invalid manifest (compiled with: ["/Users/runner/Library/Developer/Toolchains/swift-wasm-5.10.0-RELEASE.xctoolchain/usr/bin/swiftc", "-vfsoverlay", "/var/folders/lr/439_fwvd3m76p9vy50d57kcc0000gn/T/TemporaryDirectory.NZeeV5/vfs.yaml", "-L", "/Users/runner/Library/Developer/Toolchains/swift-wasm-5.10.0-RELEASE.xctoolchain/usr/lib/swift/pm/ManifestAPI", "-lPackageDescription", "-Xlinker", "-rpath", "-Xlinker", "/Users/runner/Library/Developer/Toolchains/swift-wasm-5.10.0-RELEASE.xctoolchain/usr/lib/swift/pm/ManifestAPI", "-target", "arm64-apple-macosx12.0", "-sdk", "/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk", "-F", "/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks", "-I", "/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib", "-L", "/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib", "-swift-version", "5", "-I", "/Users/runner/Library/Developer/Toolchains/swift-wasm-5.10.0-RELEASE.xctoolchain/usr/lib/swift/pm/ManifestAPI", "-sdk", "/Applications/Xcode_15.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk", "-package-description-version", "5.3.0", "/Users/runner/work/carton/carton/Tests/Fixtures/TestApp/Package.swift", "-Xfrontend", "-disable-implicit-concurrency-module-import", "-Xfrontend", "-disable-implicit-string-processing-module-impor
t", "-o", "/var/folders/lr/439_fwvd3m76p9vy50d57kcc0000gn/T/TemporaryDirectory.ivLEoP/testapp-manifest"])
<unknown>:0: error: unable to execute command: <unknown>
Swift/ErrorType.swift:200: Fatal error: Error raised at top level: Process failed with status 1.

printsLoadingMessage: Bool = true,
forwardExit: Bool = false
) throws {
let process = Foundation.Process()
process.executableURL = executableURL
process.arguments = arguments
if let environment {
process.environment = environment
Copy link
Contributor Author

@omochi omochi Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

環境変数を設定する口を開けました。
nil をセットすると、
継承するデフォルト挙動が消えるようなので、
nilの時はifで避けます。

参考:
https://developer.apple.com/documentation/foundation/process/1409412-environment

If this method isn’t used, the environment is inherited from the process that created the receiver

@omochi omochi marked this pull request as draft June 10, 2024 08:25
@omochi
Copy link
Contributor Author

omochi commented Jun 10, 2024

だめだあ
手元でちゃんとみてみよう

@omochi omochi marked this pull request as ready for review June 10, 2024 15:34
} else {
let programName = (program as NSString).lastPathComponent
if programName == "wasmtime" {
arguments += ["--dir", "."]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasmtimeのpreopenの問題の対応

@kateinoigakukun kateinoigakukun changed the title macにsnapshot版のツールチェーンを入れるときは9999問題を回避する作業をする Apply runtime library workaround for snapshot toolchains on macOS Jun 10, 2024
@kateinoigakukun kateinoigakukun merged commit 79b686c into swiftwasm:main Jun 10, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants